package com.foxzzz.deep.first;

import com.alibaba.fastjson.JSON;
import com.foxzzz.base.TreeNode;

import java.util.List;

/**
 * @author: [wujie]
 * @createTime: [2019/12/11 18:59]
 * @description:
 */
public class Solution108 {

    public TreeNode sortedArrayToBST(int[] nums) {
        return insert(nums, 0, nums.length - 1);
    }

    public TreeNode insert(int[] nums, int start, int end) {
        if (start > end) {
            return null;
        }
        int mid = (start + end) / 2;
        TreeNode t = new TreeNode(nums[mid]);
        if (mid > start) {
            t.left = insert(nums, start, mid - 1);
        }
        if (mid < end) {
            t.right = insert(nums, mid + 1, end);
        }

        return t;
    }

    public static void main(String[] args) {
        List<Integer> list = (List<Integer>) JSON.parse("[-10,-3,0,5,9]");
        int[] array = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        TreeNode treeNode = new Solution108().sortedArrayToBST(array);

        System.out.println("");


    }
}
